package com.chinasoft.test;

import com.chinasoft.creatway.Book;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Demo1 {

    @Test
    public void test1() throws Exception {
        //读取文件获取ioc容器
        ClassPathXmlApplicationContext app = new ClassPathXmlApplicationContext("application.xml");
        //根据id去取
        //HelloService helloService = (HelloService) app.getBean("helloService");
        //根据字节码对象
       // HelloService helloService = app.getBean(HelloService.class);
        //helloService.sayHello();
        //IOC
        Book book06 = (Book) app.getBean("book06");
        System.out.println(book06);
    }

    @Test
    public void testLifeCycle() throws Exception {
        //读取文件获取ioc容器
        ClassPathXmlApplicationContext app = new ClassPathXmlApplicationContext("application.xml");
        Object person = app.getBean("person");
        System.out.println(person);
        //关闭容器就销毁了
        app.close();
    }
}
